//
//  JYJMusicMiniView.m
//  HappyListen
//
//  Created by 冀永金 on 16/9/12.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "JYJMusicMiniView.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
#import "JYJProgramModel.h"
#import "JYJTAMacro.h"
#import "JYJDataTools.h"
#import "JYJMusicPlayerTools.h"
#import "JYJMusicPlayerViewController.h"
#import "Masonry.h"
@interface JYJMusicMiniView ()
@property (nonatomic, strong)  UIButton *button;

@end
@implementation JYJMusicMiniView
+ (instancetype)shareMiniView {
    static JYJMusicMiniView *miniView = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        miniView = [[JYJMusicMiniView alloc]init];
    });
    return miniView;
}
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
        self.userInteractionEnabled = YES;
    }
    return self;
}
- (void)createView {
    self.music_img = [[UIImageView alloc]init];
    [self addSubview:_music_img];
    self.music_img.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTap)];
    [self.music_img addGestureRecognizer:tap];
    [_music_img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).with.offset(5);
        make.left.equalTo(self.mas_left).with.offset(5);
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(70);
    }];
    self.music_img.image = [UIImage imageNamed:@"MyCD"];
    self.music_img.backgroundColor = [UIColor whiteColor];
    self.music_img.layer.cornerRadius = 35;
    self.music_img.clipsToBounds = YES;
}

- (void)handleTap {
    JYJMusicPlayerViewController *vcOfMusic = [JYJMusicPlayerViewController shareMusicPlayerVC];
    UIWindow *keyWindow  = [UIApplication sharedApplication].keyWindow;
    UIViewController *vc = keyWindow.rootViewController;
    [vc presentViewController:vcOfMusic animated:YES completion:^{
        self.button = [UIButton buttonWithType:UIButtonTypeCustom];
        _button.frame = CGRectMake(0, 10, 80, 40);
        [_button setTitle:@"<返回" forState:UIControlStateNormal];
        [_button addTarget:self action:@selector(handleBack) forControlEvents:UIControlEventTouchUpInside];
        [vcOfMusic.view addSubview:_button];
        self.namelLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 40, SCREEN_WIDTH, 40)];
        _namelLabel.textAlignment = 1;
        self.namelLabel.textColor = [UIColor whiteColor];
        [vcOfMusic.view addSubview:_namelLabel];
      _namelLabel.text = [JYJMusicPlayerTools shareMusicPlayerTools].programModel.music_title;
        [self.music_img sd_setImageWithURL:[NSURL URLWithString:[JYJMusicPlayerTools shareMusicPlayerTools].programModel.music_img] placeholderImage:[UIImage imageNamed:@"MyCD"]];
        
    }];
    
}
- (void)handleBack {
    JYJMusicPlayerViewController *vcOfMusic = [JYJMusicPlayerViewController shareMusicPlayerVC];
    [vcOfMusic dismissViewControllerAnimated:YES completion:^{
        self.button.hidden = YES;
        self.namelLabel.hidden = YES;
       
    }];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
